﻿
<?php 
include("inc/connection.php");
include_once("inc/constants.inc.php");
session_start();

if(!isset($_SESSION['login']) || empty($_SESSION['login']) || !isset($_SESSION['email']) || empty($_SESSION['email']))
{
	header("Location: login.php?error=invalid-access");
}


$aptitudeTestOver = false;
$technicalTestOver = false;
$disabled='';
$checked='checked';
$submitted = false;
$testOver = false;
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>Smartek online test | Test</title>
		<link rel="SHORTCUT ICON" href="img/disp/favicon.png" />
		<link rel="stylesheet" href="css/bootstrap.css"  type="text/css"/>
	</head>
	<BODY>
		<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
		<script src="js/bootstrap.js"></script>

		<div class="container">
			<img src="img/disp/logo.png" alt="">
		</div>
		<div class="container">
			<div class="row pull-right">
				<div class="span4 pull-right" >
					<div class="pull-right">
						<?php if(isset($_SESSION['name']) && !empty($_SESSION['name'])) echo  "Welcome ".$_SESSION['name']."!"; ?> | <a href="logout.php">Log out</a>
					</div>
				</div>
			</div>
		</div>
		<div style="clear:both"></div>
		<div class="container">
			<hr class="featurette-divider">
		</div>

		<div class="container">
			<div class="row">
				<div class="span12" > <!--pagination-centered-->
					<form method="GET" action="start-test.php">
						<h4>Instructions:</h4>
						<?php 
						$counter = mysql_query("SELECT COUNT(*) AS id FROM instructions");
                        $num = mysql_fetch_array($counter);
                        $count = $num["id"];
						for($i=1;$i<=$count;$i++)
							{
								$result1 = mysql_query("SELECT * FROM instructions WHERE serial_no='$i' && showInstruction='y'");

								while($row = mysql_fetch_array($result1))
								{
									echo "<b>" . $row['serial_no'].". ". $row['description']."</b></br>" ;
								}
							}
						?>
						<hr/>
						<?php 
						//if(isset($_SESSION['name']) && !empty($_SESSION['name'])) echo  "<h4>Hi, ".$_SESSION['name']."</h4>"; 
						?>
						
						<?php 
							$res = mysql_query("SELECT submitted FROM `login_details` where `userID` = $_SESSION[userID]");	
							while($row = mysql_fetch_array($res))
							{
								if($row['submitted']=="yes")
								$submitted = true;
							}
							$res = mysql_query("SELECT * FROM `answer_sheet` where `studentID` = $_SESSION[userID] and  `isReset`='no' ");	
							while($row = mysql_fetch_array($res))
							{
								$testOver = true;
							}
							if($submitted || $testOver)
							{
								echo "<h5>You have submitted the test successfully</h5></br></br>";
								echo "<a href='logout.php'>Exit</a>";	
							}
							else
							{
								$res = mysql_query("SELECT * FROM `login_details` where `userID` = $_SESSION[userID]");	
								while($row = mysql_fetch_array($res))
								{
									$domain = $row['domain'];
								}
								$res = mysql_query("SELECT * FROM `question_type` where `QTypeID` = $domain");	
								while($row = mysql_fetch_array($res))
								{
							?>
									<div class="container">
										<div class="row">										
											<div class="span9">
												<br/>
												<input type="radio" name="test_type" <?php echo $checked; ?> value="<?php echo $row['QTypeID']; ?>"> <?php echo $row['QType'];  ?>
											</div>										
										</div>
									</div>
									<br/>
									<input type="submit" class="btn" name="submit" value="Start test">
							<?php
								}
							}
						
						/*
						$res = mysql_query("SELECT * FROM `answer_sheet` where `studentID` = $_SESSION[userID] and  `isReset`='no' ");	
						while($row = mysql_fetch_array($res))
						{
							if(isset($row['typeId']) && $row['typeId']==1)
								$aptitudeTestOver = true;
							if(isset($row['typeId']) && $row['typeId']==2)
								$technicalTestOver = true;
						}
						?>
						

						<?php 
						if($aptitudeTestOver && $technicalTestOver) echo "<h5>You have attempted both Aptitude test and Technical test.</h5></br></br>"; 
						if($aptitudeTestOver && !$technicalTestOver) echo "<h5>Please choose Technical test and click \"Start test\" to proceed. Good luck for the test!</h5></br></br>"; 	
						if(!$aptitudeTestOver && $technicalTestOver) echo "<h5>Please choose Aptitude test and click \"Start test\" to proceed. Good luck for the test!</h5></br></br>"; 
						if(!$aptitudeTestOver && !$technicalTestOver) echo "<h5>Please choose the test type and click \"Start test\" to proceed. Good luck for the test!</h5></br></br>"; 

						if(!$aptitudeTestOver || !$technicalTestOver)
						{
								$result = mysql_query("SELECT * FROM `question_type`");	
								while($row = mysql_fetch_array($result))
								{	
									$disabled='';
									$checked='checked';
									if($row['QTypeID']==1 && $aptitudeTestOver){ $disabled="disabled"; $checked='';}
									if($row['QTypeID']==2 && $technicalTestOver){ $disabled="disabled"; $checked='';}	
									if($row['QTypeID']==2 && !$technicalTestOver && !$aptitudeTestOver){ $disabled=""; $checked='';}									
								
						?>
								<div class="container">
									<div class="row">										
										<div class="span9">
											<input type="radio" name="test_type" <?php echo $disabled." ".$checked; ?> value="<?php echo $row['QTypeID']; ?>"> <?php echo $row['QType'];  ?>
										</div>										
									</div>
								</div>	
								
								</br>

						<?php		
								}
							echo '<input type="submit" class="btn" name="submit" value="Start test">';
						}else
						{
							echo "<a href='logout.php'>Exit</a>";
						}
						
						*/
						?>	

					</form>
				</div>
			</div>
		</div>
		</br></br></br></br></br></br></br></br>
		<div class="container">
			<hr class="featurette-divider">
		</div>
		<div class="container marketing">
      <!-- FOOTER -->
      <footer>
        <p>&copy; 2014 SCS &middot; </p>
      </footer>

    </div><!-- /.container -->
	</body>
</html>